package com.mdd.admin.controller.customer;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICustomerListService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.CustomerListCreateValidate;
import com.mdd.admin.validate.CustomerListUpdateValidate;
import com.mdd.admin.validate.CustomerListSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.CustomerColListVo;
import com.mdd.admin.vo.CustomerListDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/customerCol")
@Api(tags = "客户列管理")
public class CustomerListController {

    @Resource
    ICustomerListService iCustomerListService;

    @GetMapping("/list")
    @ApiOperation(value="客户列列表")
    public AjaxResult<PageResult<CustomerColListVo>> list(@Validated PageValidate pageValidate,
                                                          @Validated CustomerListSearchValidate searchValidate) {
        PageResult<CustomerColListVo> list = iCustomerListService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户列详情")
    public AjaxResult<CustomerListDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CustomerListDetailVo detail = iCustomerListService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户列新增")
    @PostMapping("/add")
    @ApiOperation(value="客户列新增")
    public AjaxResult<Object> add(@Validated @RequestBody CustomerListCreateValidate createValidate) {
        iCustomerListService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户列编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CustomerListUpdateValidate updateValidate) {
        iCustomerListService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户列删除")
    @PostMapping("/del")
    @ApiOperation(value="客户列删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCustomerListService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
